home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_108 / dots-perfect / render.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  107 lines

  1. /* Render() for DotsPerfect-MX80
  2.  
  3. NB:   Render() has been recast as LONG (it was an error
  4.       to be an int). ("prtbase.i" has to be modified as well) */
  5.  
  6. #include "exec/types.h"
  7. #include "exec/nodes.h"
  8. #include "exec/lists.h"
  9. #include "exec/memory.h"
  10. #include "devices/printer.h"
  11. #include "devices/prtbase.h"
  12.  
  13. extern struct PrinterData *PD;
  14. extern struct PrinterExtendedData *PED;
  15.  
  16. LONG Render(ct,x,y,status)
  17. UBYTE ct;     /* null for B/W printers */
  18. UWORD x,y;    /* the x & y coordinates */
  19. UBYTE status; /* print status: 0=init, 1=enter pixel, 2=dump,
  20.                               3=init buffer, 4=deallocate buffer, 5=Pre-init */
  21.  
  22. {
  23.     static UWORD ROWSIZE;
  24.     static UWORD BUFSIZE;
  25.     static UWORD bufptr, offset;
  26.     static BYTE  center;
  27.     static UBYTE *ptr, bit_table[] = {128,64,32,16,8,4,2,1};
  28.     UWORD  i;
  29.     LONG    err;   /* error */
  30.  
  31.     switch(status)
  32.     {
  33.     case 0:
  34.         /* Allocate memory for printer buffer */
  35.         i = (center) ? ((PED->ped_MaxXDots - x)/2) : 0;
  36.         offset = i+4;
  37.         ROWSIZE = x+i; /* Row size required */
  38.         BUFSIZE = (6 + ROWSIZE); /*Buffer size required */
  39.         PD->pd_PrintBuf = (UBYTE *)
  40.             AllocMem(BUFSIZE*2,MEMF_PUBLIC); /* Alloc. public mem */
  41.         if(err=(PD->pd_PrintBuf == 0)) return(err);
  42.         /* Reset printer to power-up state */
  43.         if(err=(*(PD->pd_PWrite))("\033@",2)) return(err);
  44.         if(err=PWait(1,0)) return(err);
  45.         /* Select 24/216 (8/72) inch spacing */
  46.         if(err=(*(PD->pd_PWrite))("\0333\030",3)) return(err);
  47.         /* Set unidirectional print mode */
  48.         if(err=(*(PD->pd_PWrite))("\033U1",3)) return(err);
  49.         bufptr = 0;
  50.         return(0); /* Flag as all okay */
  51.         break;
  52.     
  53.     case 1:
  54.         /* Put pixel in buffer */
  55.         i = bufptr+x+4; /* Calculate which byte to use */
  56.         /* Fill print buffer*/
  57.         PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | (1 << (7-(y&7)));
  58.         PD->pd_PrintBuf[bufptr+x+offset] |= bit_table[y&7];
  59.         return(0); /* Flag as all okay */
  60.         break;
  61.         
  62.     case 2:
  63.         /* Dump buffer to printer */
  64.         if(err=(*(PD->pd_PWrite))(&(PD->pd_PrintBuf[bufptr]),
  65.                 BUFSIZE)) return(0);
  66.         bufptr = BUFSIZE - bufptr;
  67.         return(0); /* Flag as all okay */
  68.         break;
  69.     
  70.     case 3:
  71.         /* Clear and initialize buffer */
  72.         for(i=bufptr; i<bufptr+BUFSIZE; i++)
  73.             PD->pd_PrintBuf[i] = 0; /* Clear buffer */
  74.         ptr = &PD->pd_PrintBuf[bufptr];
  75.         i = BUFSIZE;
  76.         while(i--) *ptr++ = 0;
  77.         PD->pd_PrintBuf[bufptr] = 27;
  78.         PD->pd_PrintBuf[bufptr+1] = 'L';
  79.         PD->pd_PrintBuf[bufptr+2] = ROWSIZE & 0xff;
  80.         PD->pd_PrintBuf[bufptr+3] = ROWSIZE >> 8;
  81.         PD->pd_PrintBuf[bufptr+BUFSIZE-2] = 10;
  82.         PD->pd_PrintBuf[bufptr+BUFSIZE-1] = 13;
  83.         return(0); /* Flag as all okay */
  84.         break;
  85.     
  86.     case 4:
  87.         /*Free the print buffer memory */
  88.         err=(*(PD->pd_PWrite))("\033@",2); /* Reset to power-up state */
  89.         if(!err) err=(*(PD->pd_PBothReady))(); /* Wait for buffers
  90.                                 to empty */
  91.         FreeMem(PD->pd_PrintBuf,BUFSIZE*2); /* Free buffer memory */
  92.         return(err); /* Return Status */
  93.         break;
  94.         
  95.     case 5:
  96.         /* io_special flag call */
  97.         center = x & SPECIAL_CENTER; /* Set center flag */
  98.         return(0); /* Flag as all okay */
  99.         break;
  100.     
  101.     default:
  102.         return(0);
  103.  
  104.     }
  105. }
  106.  
  107.